#include <iostream>
#include <vector>

using std::vector;
using std::cout;

class Solution {
public:
    int minSubArrayLen(int target, const vector<int>& nums) {
        int sum = 0;
        int min = INT32_MAX;
        
        int subLen = 0; // 滑动窗口的长度
        int j = 0; // 滑动窗口的起始地

        for(int i = 0;i < nums.size(); ++ i)
        {
            sum += nums[i];

            while(sum >= target)
            {
                subLen = i - j + 1;
                min = min > subLen ? subLen : min;  
                sum -= nums[j++];
            }

        }
        return min == INT32_MAX ? 0 : min;
    }
};

int main(int argc, char const *argv[])
{
    Solution s;
    int min = s.minSubArrayLen(7,{2,3,1,2,4,3});
    cout << min << "\n";
    getchar();
    return 0;
}
